﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ForkCarRelationManager.db;
using ForkCarRelationManager.Business;
using ForkCarRelationManager.Utility;
using common;
namespace ForkCarRelationManager
{
    public partial class RepireDetailForm : Form
    {
        private int repireID=0;
        MaintenBI maintenBI = new MaintenBI();
        RepireBI repireBI = new RepireBI();
        public RepireDetailForm(int repireID,int handle)
        {
            InitializeComponent();
            this.repireID = repireID;
            if (repireID != 0)
            {
                initForm();
            }
            if (handle == 0)
            {
                btnsave.Show();
                btnmainten.Hide();
                labgiveup.Hide();
                TBgiveup.Hide();
                TBPlace.Enabled = true;
                RepairContenttext.Enabled = true;
                TBrequiredate.Enabled = true;
            }
            else if (handle == 1) 
            {
                btnsave.Hide();
                btnmainten.Show();
                labgiveup.Hide();
                TBgiveup.Hide();
                TBPlace.Enabled = false;
                RepairContenttext.Enabled = false;
                TBrequiredate.Enabled = false;
            }
            else if (handle == 2)
            {
                btnsave.Hide();
                btnmainten.Hide();
                labgiveup.Show();
                TBgiveup.Show();
                TBPlace.Enabled = false;
                RepairContenttext.Enabled = false;
                TBrequiredate.Enabled = false;
            }

        }
        private void initForm()
        {
            DataTable repiretable = repireBI.getRepiredata(repireID);
            TBclient.Text = repiretable.Rows[0]["ClientName"].ToString();
            TBConName.Text = repiretable.Rows[0]["ContactName"].ToString();
            TBConphone.Text = repiretable.Rows[0]["ContactPhone"].ToString();
            TBPlace.Text = repiretable.Rows[0]["ClientPlace"].ToString();
            TBCompany.Text = repiretable.Rows[0]["ScompanyName"].ToString();
            TBrequiredate.Text = repiretable.Rows[0]["RequiredDate"].ToString();
            RepairContenttext.Text = repiretable.Rows[0]["RepairContent"].ToString();
            TBgiveup.Text = repiretable.Rows[0]["GiveUpReson"].ToString();
        }
        private void RepireDetailForm_Load(object sender, EventArgs e)
        {

        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (RepairContenttext.Text.Trim() == "" || TBrequiredate.Text.Trim() == "")
            {
                MessageBox.Show("打星号的内容不能为空");
            }
            else
            {
               if( repireBI.updateRepiredetails(repireID,TBPlace.Text.Trim(),RepairContenttext.Text.Trim(),TBrequiredate.Text.Trim()))
               {
                   MessageBox.Show("修改成功");
                   this.DialogResult=DialogResult.Yes;
               }
                else
               {
                   MessageBox.Show("修改失败");
               }
            }
        }

        private void btnmainten_Click(object sender, EventArgs e)
        {
            int maintenid =repireBI. GetmaintenIDbyrepireID(repireID);
         
            if (maintenid!=0)
            {
                MaintenInforForm mdForm = new MaintenInforForm(Convert.ToInt32(maintenid));
                mdForm.Show();
            }
        }
    }
}
